package com.shimao.celnet.payment.service.impl.apiservice;


import com.shimao.celnet.payment.common.exception.HttpConnectionUtil;
import com.shimao.celnet.payment.config.ConstantConfig;
import com.shimao.celnet.payment.model.PPay;
import com.shimao.celnet.payment.model.PPayCUPUser;
import com.shimao.celnet.payment.model.PPayCust;
import com.shimao.celnet.payment.util.SignCheckUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

/**
 * 通联支付平台的各个接口调用类
 * christ
 */
@Service
public class CallOut_TLPublicService {
    protected Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private ConstantConfig constantConfig;

    //普通支付
    public Map<String, String> pay(String trxamt, String reqsn, String paytype, String body, String remark, String acct, String notify_url, PPayCust pPayCus) throws Exception {
        System.out.println(constantConfig.getTlApiURL());
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/pay");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        logger.info("version"+pPayCus.getVersion());
        params.put("trxamt", trxamt);
        logger.info("trxamt"+trxamt);
        params.put("reqsn", reqsn);
        params.put("paytype", paytype);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("body", body);
        logger.info("body***********************"+body);
        params.put("remark", remark);
        logger.info("remark"+remark);
        params.put("acct", acct);
        logger.info("acct"+acct);
        params.put("notify_url", notify_url);
        logger.info("notify_url"+notify_url);
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        logger.info("params"+params.toString());
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }
    //普通支付
    public Map<String, String> payGroup(String trxamt, String reqsn, String paytype, String body, String remark, String acct, String notify_url, PPayCust pPayCus) throws Exception {
        System.out.println(constantConfig.getTlApiURL());
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/pay");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        logger.info("version"+pPayCus.getVersion());
        params.put("trxamt", trxamt);
        logger.info("trxamt"+trxamt);
        params.put("reqsn", reqsn);
        params.put("paytype", paytype);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("body", body);
        logger.info("body***********************"+body);
        params.put("remark", remark);
        logger.info("remark"+remark);
        params.put("acct", acct);
        logger.info("acct"+acct);
        params.put("orgid", "560588053990TJR");
        params.put("notify_url", notify_url);
        logger.info("notify_url"+notify_url);
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        logger.info("params"+params.toString());
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }
    //微信小程序支付 、公众号
    public Map<String, String> payWechatApp(String trxamt, String reqsn, String paytype, String body, String remark, String acct, String sub_appid, String notify_url, PPayCust pPayCus) throws Exception {
        System.out.println(constantConfig.getTlApiURL());
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/pay");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        logger.info("version"+pPayCus.getVersion());
        params.put("trxamt", trxamt);
        logger.info("trxamt"+trxamt);
        params.put("reqsn", reqsn);
        params.put("paytype", paytype);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("body", body);
        logger.info("body***********************"+body);
        params.put("remark", remark);
        logger.info("remark"+remark);
        params.put("acct", acct);
        logger.info("acct"+acct);
        params.put("sub_appid", sub_appid);
        params.put("orgid", "560588053990TJR");
        logger.info("sub_appid"+acct);
        params.put("notify_url", notify_url);
        logger.info("notify_url"+notify_url);
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        logger.info("params"+params.toString());
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }
    //公众号
    public Map<String, String> payWechatOfficialAccounts(String trxamt, String reqsn, String paytype, String body, String remark, String acct, String sub_appid, String notify_url, PPayCust pPayCus) throws Exception {
        System.out.println(constantConfig.getTlApiURL());
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/pay");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        logger.info("version"+pPayCus.getVersion());
        params.put("trxamt", trxamt);
        logger.info("trxamt"+trxamt);
        params.put("reqsn", reqsn);
        params.put("paytype", paytype);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("body", body);
        logger.info("body***********************"+body);
        params.put("remark", remark);
        logger.info("remark"+remark);
        params.put("acct", acct);
        logger.info("acct"+acct);
        params.put("sub_appid", acct);
        logger.info("sub_appid"+acct);
        params.put("notify_url", notify_url);
        logger.info("notify_url"+notify_url);
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        logger.info("params"+params.toString());
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }

    //微信支付
    public Map<String, String> payWeChat(String trxamt, String reqsn, String paytype, String body, String remark, PPay pay, String notify_url, PPayCust pPayCus) throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/h5pay");
        System.out.println(constantConfig.getTlApiURL() + "/h5pay");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        params.put("trxamt", trxamt);
        params.put("reqsn", reqsn);
        params.put("paytype", paytype);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("body", body);
        params.put("remark", remark);
        params.put("notify_url", notify_url);
        params.put("apptype", pay.getPayAppType());
        params.put("appname", pay.getPayAppName());
        params.put("apppackage", pay.getPayAppPackage());
        params.put("cusip", pay.getPayCusip());
        //params.put("randomstr", pay.getPayRandomstr());
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;

    }


    public Map<String, String> cancel(long trxamt, String reqsn, String oldtrxid, String oldreqsn, PPayCust pPayCus) throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/cancel");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        params.put("trxamt", String.valueOf(trxamt));
        params.put("reqsn", reqsn);
        params.put("oldtrxid", oldtrxid);
        params.put("oldreqsn", oldreqsn);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }

    /**
     * @param trxamt
     * @param reqsn
     * @param oldtrxid
     * @param oldreqsn
     * @return
     * @throws Exception
     */
    public Map<String, String> refund(long trxamt, String reqsn, String oldtrxid, String oldreqsn, PPayCust pPayCus) throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/refund");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCus.getCustId());
        params.put("appid", pPayCus.getAppId());
        params.put("version", pPayCus.getVersion());
        params.put("trxamt", String.valueOf(trxamt));
        params.put("reqsn", reqsn);
        params.put("oldreqsn", oldreqsn);
        params.put("oldtrxid", oldtrxid);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("sign", SignCheckUtil.sign(params, pPayCus.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCus.getAppKey());
        return map;
    }

    public Map<String, String> query(String reqsn, String trxid, PPayCust pPayCust) throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL() + "/query");
        http.init();
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("cusid", pPayCust.getCustId());
        params.put("appid", pPayCust.getAppId());
        params.put("version", pPayCust.getVersion());
        params.put("reqsn", reqsn);
        params.put("trxid", trxid);
        params.put("randomstr", SignCheckUtil.getValidatecode(8));
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }


    public static Map<String, String> handleResult(String result, String appKey) throws Exception {
        Map map = SignCheckUtil.json2Obj(result, Map.class);
        if (map == null) {
            throw new Exception("返回数据错误");
        }
        if ("SUCCESS".equals(map.get("retcode"))) {
            TreeMap tmap = new TreeMap();
            tmap.putAll(map);
            String sign = tmap.remove("sign").toString();
            String sign1 = SignCheckUtil.sign(tmap, appKey);
            if (sign1.toLowerCase().equals(sign.toLowerCase())) {
                return map;
            } else {
                throw new Exception("验证签名失败");
            }

        } else {
            throw new Exception(map.get("retmsg").toString());
        }
    }

    /***
     * 收银宝快捷：申请签约
     * @return
     */
    public Map<String,String> agreeapply(PPayCUPUser payCUPUser, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/agreeapply");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("meruserid",payCUPUser.getPayMeruserid());
        params.put("accttype",payCUPUser.getPayAccttype());
        params.put("acctno",payCUPUser.getPayAcctno());
        params.put("idno",payCUPUser.getPayIdno());
        params.put("acctname",payCUPUser.getPayAcctname());
        params.put("mobile",payCUPUser.getPayMobile());
        if("02".equals(payCUPUser.getPayAccttype()) ){
            params.put("cvv2", payCUPUser.getPayCvv2());
            params.put("validdate", payCUPUser.getPayValiddate());
        }

        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：重发申请签约验证码
     * @return
     */
    public Map<String,String> ResendSMS(PPayCUPUser payCUPUser, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/agreesms");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("meruserid",payCUPUser.getPayMeruserid());
        params.put("accttype",payCUPUser.getPayAccttype());
        params.put("acctno",payCUPUser.getPayAcctno());
        params.put("idno",payCUPUser.getPayIdno());
        params.put("acctname",payCUPUser.getPayAcctname());
        params.put("mobile",payCUPUser.getPayMobile());
        if("02".equals(payCUPUser.getPayAccttype())){  //信用卡才使用该字段
            params.put("cvv2", payCUPUser.getPayCvv2());
            params.put("validdate", payCUPUser.getPayValiddate());
        }
        if(payCUPUser.getPayThpinfo()!= null && !"".equals(payCUPUser.getPayThpinfo()) ){
            params.put("thpinfo", payCUPUser.getPayThpinfo());
        }
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：确认签约绑卡
     * @return
     */
    public Map<String,String> agreeconfirm(PPayCUPUser payCUPUser, PPayCust pPayCust)throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/agreeconfirm");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("meruserid",payCUPUser.getPayMeruserid());
        params.put("accttype",payCUPUser.getPayAccttype());
        params.put("acctno",payCUPUser.getPayAcctno());
        params.put("idno",payCUPUser.getPayIdno());
        params.put("acctname",payCUPUser.getPayAcctname());
        params.put("mobile",payCUPUser.getPayMobile());
        if("02".equals(payCUPUser.getPayAccttype())){  //信用卡才使用该字段
            params.put("cvv2", payCUPUser.getPayCvv2());
            params.put("validdate", payCUPUser.getPayValiddate());
        }
        params.put("smscode", payCUPUser.getSmscode());
        if(payCUPUser.getPayThpinfo()!= null && !"".equals(payCUPUser.getPayThpinfo())){
            params.put("thpinfo", payCUPUser.getPayThpinfo());
        }
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;

    }

    /***
     * 收银宝快捷：支付申请
     * @return
     */
    public Map<String,String> payapply(String orderid, String agreeid, String amount, String subject, String trxreserve, String notify_url, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/payapplyagree");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid", orderid);
        params.put("amount", amount);
        params.put("subject", subject);       //订单的展示标题
        params.put("trxreserve", trxreserve);  //交易备注   用于用户订单个性化信息  交易完成通知会带上本字段
        params.put("notifyurl", notify_url);
        params.put("currency","CNY");  //币种    通联暂只支持CNY
        params.put("validtime","30");  //订单有效时间   最大1440分钟,单位：分钟 默认5分钟
        params.put("agreeid",agreeid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：确认支付
     * @return
     */
    public Map<String,String> pay(String orderid, String agreeid, String smscode, String thpinfo, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/payagreeconfirm");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid", orderid);
        params.put("smscode", smscode);
        if(thpinfo!= null &&!"".equals(thpinfo)){
            params.put("thpinfo", thpinfo);
        }
        params.put("agreeid",agreeid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：重发支付验证码
     * @return
     */
    public Map<String,String> ResendPaySMS(String orderid,String agreeid,String thpinfo, PPayCust pPayCust) throws Exception {
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/paysmsagree");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid", orderid);
        if(thpinfo!= null &&!"".equals(thpinfo)){
            params.put("thpinfo", thpinfo);
        }
        params.put("agreeid",agreeid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：解绑银行卡
     * @return
     */
    public Map<String,String> unbind(String agreeid, PPayCust pPayCust)  throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/unbind");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");

        params.put("agreeid",agreeid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /***
     * 收银宝快捷：交易撤销
     * @return
     */
    public Map<String,String> cancelCUP(String orderid, Long trxamt, String oldorderid, String oldtrxid, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/cancel");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid",orderid);//绑卡返回的agreeid
        params.put("trxamt",String.valueOf(trxamt));//绑卡返回的agreeid
        params.put("oldorderid",oldorderid);//绑卡返回的agreeid
        params.put("oldtrxid",oldtrxid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /**
     *
     * @Author Galen
     * @Description //TODO 收银宝快捷：交易退款
     * @Date 10:32 2018/11/23
     * @Param [trxamt, orderid, oldorderid, oldtrxid, pPayCust]
     * @return java.util.Map<java.lang.String,java.lang.String>
     */
    public Map<String,String> refundCUP(Long trxamt, String orderid, String oldorderid, String oldtrxid, PPayCust pPayCust) throws Exception{

        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/refund");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid",orderid);//绑卡返回的agreeid
        params.put("trxamt",String.valueOf(trxamt));//绑卡返回的agreeid
        params.put("oldorderid",oldorderid);//绑卡返回的agreeid
        params.put("oldtrxid",oldtrxid);//绑卡返回的agreeid
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /**
     *
     * @Author Galen
     * @Description //TODO 收银宝快捷：交易查询
     * @Date 10:31 2018/11/23
     * @Param [orderid, trxid, pPayCust]
     * @return java.util.Map<java.lang.String,java.lang.String>
     */
    public Map<String,String> queryCUP(String orderid, String trxid, PPayCust pPayCust)  throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/query");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("orderid",orderid);//商户的交易订单号
        params.put("trxid",trxid);//平台交易流水
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    /**
     *
     * @Author Galen
     * @Description //TODO 收银宝快捷：协议查询
     * @Date 10:29 2018/11/23
     * @Param [meruserid, payCust]
     * @return java.util.Map<java.lang.String,java.lang.String>
     */
    public Map<String,String> agreequery(String meruserid, PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlApiURL1() + "/agreequery");
        http.init();
        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("version", pPayCust.getVersion());
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("meruserid",meruserid);//商户用户号
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }

    public Map<String, String> getFileUrl(PPayCust pPayCust) throws Exception{
        HttpConnectionUtil http = new HttpConnectionUtil(constantConfig.getTlTrxFileURL());
        http.init();
        //获取前一天日期
        Calendar c = Calendar.getInstance();
        Date date = new Date();
        c.setTime(date);
        int day=c.get(Calendar.DATE);
        c.set(Calendar.DATE,day-1);
        String dayBefore=new SimpleDateFormat("yyyyMMdd").format(c.getTime());

        TreeMap<String,String> params = new TreeMap<String,String>();
        params.put("appid", pPayCust.getAppId());
        params.put("cusid", pPayCust.getCustId());
        params.put("date", dayBefore);
        params.put("randomstr", System.currentTimeMillis()+"");
        params.put("sign", SignCheckUtil.sign(params, pPayCust.getAppKey()));
        byte[] bys = http.postParams(params, true);
        String result = new String(bys, "UTF-8");
        Map<String, String> map = handleResult(result, pPayCust.getAppKey());
        return map;
    }
}
